package com.greendragon.persistence.dao.impl; 

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.greendragon.persistence.dao.ISiteInfoDao;
import com.greendragon.persistence.domain.SiteInfo;

/** 
 * @author wulibin, exceptsky@gmail.com, 2011-9-8 下午11:25:33
 * 
 */
public class SiteInfoDaoImpl extends HibernateDaoSupport implements ISiteInfoDao{
	private static Logger          logger           = Logger.getLogger(SiteInfoDaoImpl.class);
	
	@Override
	public void add(SiteInfo siteInfo) {
		//只存在一个站点信息
		try {
			getHibernateTemplate().save(siteInfo);
		} catch (Exception e) {
			logger.error(e);
		}
		
	}

	@Override
	public void update(SiteInfo siteInfo) {
		try {
			getHibernateTemplate().update(siteInfo);
		} catch (Exception e) {
			logger.error(e);
		}
		
	}
	
	@Override
	@SuppressWarnings("unchecked")
	public SiteInfo get() {
		List<SiteInfo> list;
		try {
			list = getHibernateTemplate().find("from SiteInfo");
		} catch (Exception e) {
			logger.error(e);
			return null;
		}
		if(list.size()>0){
			return list.get(0);
		}else{
			return null;
		}
	}
}
 